package tests;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

import utils.DBManager;
import utils.ImageUtils;
import featuresProcessing.ShapeDetector;

public class ShapeMatchingTest {

	public static void main(String[] args) {

		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		ShapeDetector sd = new ShapeDetector();
		Mat image = Highgui.imread("C:/Users/Luca/Desktop/a.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
		Mat image2 = Highgui.imread("C:/Users/Luca/Desktop/d.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);

		Mat ic1 = sd.getDescriptors(image);
				Mat ic2 = sd.getDescriptors(image2);

//		Mat ic2;
//		Statement stmt;
//		
//		try {
//			
//			stmt = DBManager.getConnection().createStatement();
//			stmt.execute("select id, shape_descriptors, name from "+"tree_finder.species where id=1");
//			ResultSet rs = stmt.getResultSet();
//			rs.next();
//
//			ByteArrayInputStream bais = new ByteArrayInputStream(rs.getBytes(2));
//			ObjectInputStream ois = new ObjectInputStream(bais);
//			int[] shapeDescriptorsBytes = (int[])ois.readObject();
//			Mat shapeDescriptors = new Mat(new Size(1, shapeDescriptorsBytes.length/(2*1)), 12);
//			shapeDescriptors.put(0, 0, shapeDescriptorsBytes);
//			ic2 = shapeDescriptors;
//			bais.close();
//			ois.close();
//
			System.out.println(Imgproc.matchShapes(ic1, ic2, Imgproc.CV_CONTOURS_MATCH_I3, 0));
//			
//		} catch (SQLException | IOException | ClassNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}

}
